/*
 * Tutorial - the overly text-as-image-heavy introduction to the game
 *
 * Copyright 2007 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Point;
import flash3f.InputHandler;
import flash3f.Images;
import flash.Lib;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

class Tutorial
{

	public static var cur : Bitmap;
	public static var selections : Array<Shiner>;
	public static var selectmap = [ new Tut1(),
									new Tut2(),
									new Tut3(),
									new Tut4(),
									new Tut5(),
									new Tut6(),
									new Tut7(),
									new Tut8(),
									new Tut9()];
	
	public static function buildshiners()
	{
		selections = new Array();
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Introduction"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Objectives"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Castles"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Transports"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Creeps"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Territory"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Towers"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Upgrades"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["Scoring"])));		
		selections.push(new Shiner(Fonts.verdanaitalic.gen(["*END*"])));		
	}
	
	public static function start()
	{
		ComponentManager.removerough(Title);
		
		for (n in 0...Lib.current.numChildren)
		{
			Lib.current.removeChildAt(0);
		}				
		
		buildshiners();
		
		cur = new Bitmap();
		Lib.current.addChild(cur);
		cur.bitmapData = selectmap[0];
		cur.x = Lib.current.stage.stageWidth - (cur.bitmapData.width * 1.3);

		for (n in 0...selections.length)
		{
			selections[n].x = 72;
			selections[n].y = 42 + 30*n;
		}
		selections[selections.length-1].y = 42 + 30 * selections.length;

	}
			
	public static function up()
	{

		Shiner.up();
	
		if (InputHandler.click)
		{
		
			for (n in 0...selections.length)
			{
			if (selections[n].bitmapData.rect.contains
				(InputHandler.cursx-selections[n].x,InputHandler.cursy-selections[n].y))
				{
					if (n>8)
						ComponentManager.remove(Tutorial);
					else
						cur.bitmapData = selectmap[n];
				}
			}
		
		}	
			
	}
	
	public static function end()
	{
		for (n in 0...Lib.current.numChildren)
		{
			Lib.current.removeChildAt(0);
		}
		ComponentManager.add(Title);
	}

}

/*class Tut1 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut2 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut3 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut4 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut5 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut6 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut7 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut8 extends BitmapData 
{	public function new()	{super(0,0);}}
class Tut9 extends BitmapData 
{	public function new()	{super(0,0);}}
*/
